package controller;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JTable;

import model.ThanhVienModel;
import dao.ThanhVienDao;

public class DangNhapController extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse res){
		try {
			String userName = req.getParameter("username");
			String password = req.getParameter("password");
			String pageNext = "";
			
			
			
			ThanhVienModel model = ThanhVienDao.getThanhVienByTenDnAndPassword(userName, password);
			
			
			
			if(model != null){
				//req.setAttribute("tenDangNhap", userName);
				//req.setAttribute("vaitro", model.getVaitro());
				
				req.getSession().setAttribute("tenDangNhap", userName);
				req.getSession().setAttribute("vaitro", model.getVaitro());
				pageNext = "homePage.jsp";
			}else{
				req.setAttribute("logFail", "Login Fail");
				pageNext= "dangNhap.jsp";
			}
			RequestDispatcher reqd = req.getRequestDispatcher(pageNext);
			reqd.forward(req, res);
			
			
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse res){
		doGet(req, res);
	}
}
